﻿/*
 * Сделано в SharpDevelop.
 * Пользователь: CrMosk
 * Дата: 10.05.2013
 * Время: 14:05
 *  
 */
using System;
using System.Collections.Generic;

namespace Region.Utils
{
  /// <summary>
  /// Description of ExportXLSX.
  /// </summary>
  /*public class ExportXML: Export
  {
        static public bool SetCellText(System.Xml.XmlNode Cell,Object Text,String Type)
        {
            return true;
        }
        static public String getCellText(System.Xml.XmlElement Cell)
        {
            if (Cell==null) return null;            
            if (Cell.Name!="Cell") return null;
            System.Xml.XmlNodeList DataList = Cell.GetElementsByTagName("Data");
            if (DataList.Count==0) return null;
            System.Xml.XmlElement Data = (System.Xml.XmlElement)DataList[0];
            return Data.InnerText; 
        }
        static public bool setCell(System.Xml.XmlElement Cell,Object Value)
        {
            if (Cell == null) return false;
            if (Cell.Name != "Cell") return false;
            System.Xml.XmlNodeList DataList = Cell.GetElementsByTagName("Data");
            if (DataList.Count == 0) return false;
            System.Xml.XmlElement Data = (System.Xml.XmlElement)DataList[0];
            if (Value is Int32)
            {
            }
            else
            {
                /*new System.Xml.XmlAttribute();
                Data.InnerText = Value.ToString();
                Data.Attributes. ["ss:Type"] = "String";            *
            }
            return true;
        }
        static public bool InsertText(System.Xml.XmlElement Element, Dictionary<String, Object> Poles)
        {
            foreach (System.Xml.XmlElement Cell in Element.GetElementsByTagName("Cell"))
            {
                String Text = getCellText(Cell);
                if (Text != null)
                {
                    bool Edit = false;
                    foreach(KeyValuePair<String, Object> Pole in Poles)
                        if (Text==Pole.Key)// Полное совпадение строки
                        {
                        }
                        else if (Text.IndexOf(Pole.Key)>=0) // Частичное совпадение
                        {
                            Text = Text.Replace(Pole.Key, Pole.Value.ToString());
                            Edit = true;
                        }
                    if (Edit)
                    {
                        setCell(Cell, Text);
                    }
                }
            } 
            return true;

        }
        static public bool ExportExcelXML(String Template, String Out, Dictionary<String, Object> Poles, List<Dictionary<String, Object>> Lines)
        {            
            System.Xml.XmlDocument Doc = new System.Xml.XmlDocument();
            Doc.LoadXml(Template);
            foreach (System.Xml.XmlElement Worksheet in Doc.GetElementsByTagName("Worksheet"))
            {
                InsertText(Worksheet, Poles);                
            }            
            Doc.Save(Out);
            return true;
        }
        static public bool ExportExcelXML(byte[] Template, String Out, Dictionary<String, Object> Poles, List<Dictionary<String, Object>> Lines)
        {

            Template = Export.DecodeGZ(Template);
            String XML = Encoding.GetEncoding("utf-8").GetString(Template);
            return ExportExcelXML(XML, Out, Poles, Lines);
        }

    }*/
}
